package org.dromara.xyyw.controller;

import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.xyyw.domain.bo.XyywShopProductCommentBo;
import org.dromara.xyyw.domain.query.XyywShopProductCommentQuery;
import org.dromara.xyyw.domain.vo.XyywShopProductCommentVo;
import org.dromara.xyyw.service.IXyywShopProductCommentService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 商铺商品评论
 *
 * @author yf
 * @date 2024-05-29
 */
@Validated
@RestController
@RequestMapping("/xyyw/shopProductComment")
public class XyywShopProductCommentController extends BaseController {

    @Autowired
    private IXyywShopProductCommentService xyywShopProductCommentService;

    /**
     * 查询商铺商品评论列表
     */
    @SaCheckPermission("xyyw:shopProductComment:list")
    @GetMapping("/list")
    public TableDataInfo<XyywShopProductCommentVo> list(XyywShopProductCommentQuery query) {
        return xyywShopProductCommentService.queryPageList(query);
    }

    /**
     * 导出商铺商品评论列表
     */
    @SaCheckPermission("xyyw:shopProductComment:export")
    @Log(title = "商铺商品评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(XyywShopProductCommentQuery query, HttpServletResponse response) {
        List<XyywShopProductCommentVo> list = xyywShopProductCommentService.queryList(query);
        ExcelUtil.exportExcel(list, "商铺商品评论", XyywShopProductCommentVo.class, response);
    }

    /**
     * 获取商铺商品评论详细信息
     *
     * @param commentId 主键
     */
    @SaCheckPermission(value = {"xyyw:shopProductComment:query", "xyyw:shopProductComment:edit"}, mode = SaMode.OR)
    @GetMapping("/{commentId}")
    public R<XyywShopProductCommentVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Integer commentId) {
        return R.ok(xyywShopProductCommentService.queryById(commentId));
    }

    /**
     * 新增商铺商品评论
     */
    @SaCheckPermission("xyyw:shopProductComment:add")
    @Log(title = "商铺商品评论", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody XyywShopProductCommentBo bo) {
        return toAjax(xyywShopProductCommentService.insertByBo(bo));
    }

    /**
     * 修改商铺商品评论
     */
    @SaCheckPermission("xyyw:shopProductComment:edit")
    @Log(title = "商铺商品评论", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody XyywShopProductCommentBo bo) {
        return toAjax(xyywShopProductCommentService.updateByBo(bo));
    }

    /**
     * 删除商铺商品评论
     *
     * @param commentIds 主键串
     */
    @SaCheckPermission("xyyw:shopProductComment:remove")
    @Log(title = "商铺商品评论", businessType = BusinessType.DELETE)
    @DeleteMapping("/{commentIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Integer[] commentIds) {
        return toAjax(xyywShopProductCommentService.deleteWithValidByIds(List.of(commentIds)));
    }
}
